from .utils.error_response import *
from app.url.api_url import *
from .utils.wlog import *

create_log_path(current_date())
app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=['*'],
    allow_credentials=True,
    allow_methods=['*'],
    allow_headers=['*'],
)


@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
    start_time = time.time()
    response = await call_next(request)
    process_time = time.time() - start_time
    response.headers["X-Process-Time"] = str(process_time)
    return response


app.add_exception_handler(RequestValidationError, request_validation_exception_handler)
app.include_router(api_router)
